package com.study.zzedu.adapter;

import android.annotation.SuppressLint;
import android.graphics.Color;
import android.os.Build;
import android.support.annotation.NonNull;
import android.support.annotation.RequiresApi;
import android.support.v7.widget.RecyclerView;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import com.study.zzedu.R;
import com.study.zzedu.entity.Msg;
import com.study.zzedu.entity.TuitionModel;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

public class TuitionAdapter extends RecyclerView.Adapter<TuitionAdapter.ViewHolder> {
    private List<TuitionModel> m;
    private DateFormat df = new SimpleDateFormat("yyyy-MM-dd");

    public class ViewHolder extends RecyclerView.ViewHolder
    {
        private TextView tv_semester,tv_tuition_status,tv_tuition_time,tv_tuition_cost,tv_tuition_tui;
        public ViewHolder(View view){
            super(view);
            tv_semester = (TextView) view.findViewById(R.id.tv_semester);
            tv_tuition_status = (TextView)  view.findViewById(R.id.tv_tuition_type);
            tv_tuition_time = (TextView)  view.findViewById(R.id.tv_tuition_time);
            tv_tuition_cost = (TextView)  view.findViewById(R.id.tv_tuition_cost);
            tv_tuition_tui = (TextView)  view.findViewById(R.id.tv_tuition_tui);
        }
    }

    public TuitionAdapter(List<TuitionModel> tuitionModel) {
        m = tuitionModel;
    }

    public ViewHolder onCreateViewHolder(ViewGroup parent, int Viewtype) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.tuition_item, parent, false);
        ViewHolder holder = new ViewHolder(view);
        return holder;
    }
    @RequiresApi(api = Build.VERSION_CODES.M)
    @SuppressLint("ResourceAsColor")
    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        TuitionModel tuitionModel = m.get(position);
        holder.tv_semester. setText(tuitionModel.getSemester());
        holder.tv_tuition_status. setText(tuitionModel.getTuitionStatus());
        ;
        holder.tv_tuition_time. setText(df.format(new Date(Long.valueOf(tuitionModel.getDate()))));
        holder.tv_tuition_cost. setText("￥"+tuitionModel.getCost());
        holder.tv_tuition_tui. setText("￥"+tuitionModel.getTui());
    }


    public int getItemCount() {
        return m.size();
    }
}